$(document).ready(function () {
    function getRootmenu() {

        console.log("2222222222222222222");
        $.ajax({
            type: "get", dataType: "json", url: "/common/getmenu", success: function (data) {
                var m = "";
                if (data.size > 0) {
                    for (j = 0; j < data.size; j++) {
                        if (data.menus_node[j].parent_id == -1) {
                            if (data.menus_node[j].ishas_son == 1) {
                                m = m + "<li roletype='2' id='" + data.menus_node[j].node_id + "' class='dropDown dropDown_hover'>" + "<a class='dropDown_A' href='" + data.menus_node[j].node_url + "'>" + data.menus_node[j].node_showname + "<i class='Hui-iconfont' >" + '' + "</i></a></li>";
                            } else {
                                m = m + "<li roletype='2' id='" + data.menus_node[j].node_id + "' class='dropDown dropDown_hover'>" + "<a class='dropDown_A' href='" + data.menus_node[j].node_url + "'>" + data.menus_node[j].node_showname + "</a></li>";
                            }
                        }
                    }
                }
                $('#ulmenu').html(m);
                $("#ulmenu li").bind('mouseover', function (e) {
                    getSonMenu(this, e)
                });
            }
        });
    }

    getRootmenu();

    function getSonMenu(event) {
        var parentId = $(event).attr("id");
        var roletype = $(event).attr("roletype");
        if (roletype == "2") $(event).addClass("hover open");
        if (roletype == "1") $(event).addClass("open");
        if ($(event).find("li").length > 0 || roletype == "0") return;
        $.ajax({
            type: "get",
            dataType: "json",
            url: "/common/getSonMenu?parentId=" + parentId,
            success: function (result) {
                var parentId = $(event).attr("id");
                $('#' + parentId).html($('#' + parentId + ' >a'))
                $('#'+parentId).html("");
                var a = "<ul class='dropDown-menu menu radius box-shadow'>";
                var b = "</ul>";
                var c = "";
                $.each(result, function (i) {
                    if(result[i].isnewblank == 1 && result[i].ishas_son == 1)
                    {
                        c = c + "<li roletype='" + result[i].ishas_son + "' id=" + result[i].node_id + "><a href='" + result[i].node_url + "' target='_blank'>" + result[i].node_showname + "<i class='arrow Hui-iconfont'></i></a></li>";
                    }
                    if(result[i].isnewblank == 1 && result[i].ishas_son == 0){
                        c = c + "<li roletype='" + result[i].ishas_son + "' id=" + result[i].node_id + "><a href='" + result[i].node_url + "' target='_blank'>" + result[i].node_showname + "</a></li>";
                    }                    if(result[i].isnewblank == 0 && result[i].ishas_son == 1){                            c = c + "<li roletype='" + result[i].ishas_son + "' id=" + result[i].node_id + "><a href='" + result[i].node_url + "'>" + result[i].node_showname + "<i class='arrow Hui-iconfont'></i></a></li>";                    }                    if(result[i].isnewblank == 0 && result[i].ishas_son == 0){                            c = c + "<li roletype='" + result[i].ishas_son + "' id=" + result[i].node_id + "><a href='" + result[i].node_url + "'>" + result[i].node_showname + "</a></li>";                    }                });                $('#' + parentId).append(a + c + b);                $("#ulmenu li").unbind('mouseover');                $("#ulmenu li").bind('mouseover', function (e) {                    getSonMenu(this, e)                });            }, error: function (result) {                alert(result.responseText);            }        });    } });



$(document).ready(function () {
    var data = [];

    function getRootmenu() {
        console.log("1111111111111111");
        var data1 = {
            "code": 2000,
            "data": [
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class22",
                            "interValue": "url22",
                            "menuId": 5,
                            "menuUrl": "url22",
                            "parentId": 1
                        },
                        {
                            "children": [],
                            "iconClass": "class33",
                            "interValue": "url33",
                            "menuId": 6,
                            "menuUrl": "url33",
                            "parentId": 1
                        }
                    ],
                    "iconClass": "class1",
                    "interValue": "url1",
                    "menuId": 1,
                    "menuUrl": "url1",
                    "parentId": -1
                },
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class22",
                            "interValue": "url22",
                            "menuId": 5,
                            "menuUrl": "url22",
                            "parentId": 1
                        },
                        {
                            "children": [],
                            "iconClass": "class33",
                            "interValue": "url33",
                            "menuId": 6,
                            "menuUrl": "url33",
                            "parentId": 1
                        }
                    ],
                    "iconClass": "class1",
                    "interValue": "url1",
                    "menuId": 1,
                    "menuUrl": "url1",
                    "parentId": -1
                },
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class44",
                            "interValue": "url44",
                            "menuId": 7,
                            "menuUrl": "url44",
                            "parentId": 2
                        },
                        {
                            "children": [],
                            "iconClass": "class55",
                            "interValue": "url55",
                            "menuId": 8,
                            "menuUrl": "url55",
                            "parentId": 2
                        },
                        {
                            "children": [],
                            "iconClass": "class11",
                            "interValue": "url11",
                            "menuId": 9,
                            "menuUrl": "url11",
                            "parentId": 2
                        }
                    ],
                    "iconClass": "class2",
                    "interValue": "url2",
                    "menuId": 2,
                    "menuUrl": "url2",
                    "parentId": -1
                },
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class22",
                            "interValue": "url22",
                            "menuId": 10,
                            "menuUrl": "url22",
                            "parentId": 3
                        },
                        {
                            "children": [],
                            "iconClass": "class33",
                            "interValue": "url33",
                            "menuId": 11,
                            "menuUrl": "url33",
                            "parentId": 3
                        },
                        {
                            "children": [],
                            "iconClass": "class44",
                            "interValue": "url44",
                            "menuId": 12,
                            "menuUrl": "url44",
                            "parentId": 3
                        },
                        {
                            "children": [],
                            "iconClass": "class55",
                            "interValue": "url55",
                            "menuId": 13,
                            "menuUrl": "url55",
                            "parentId": 3
                        }
                    ],
                    "iconClass": "class3",
                    "interValue": "url3",
                    "menuId": 3,
                    "menuUrl": "url3",
                    "parentId": -1
                },
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class22",
                            "interValue": "url22",
                            "menuId": 5,
                            "menuUrl": "url22",
                            "parentId": 1
                        },
                        {
                            "children": [],
                            "iconClass": "class33",
                            "interValue": "url33",
                            "menuId": 6,
                            "menuUrl": "url33",
                            "parentId": 1
                        }
                    ],
                    "iconClass": "class1",
                    "interValue": "url1",
                    "menuId": 1,
                    "menuUrl": "url1",
                    "parentId": -1
                },
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class44",
                            "interValue": "url44",
                            "menuId": 7,
                            "menuUrl": "url44",
                            "parentId": 2
                        },
                        {
                            "children": [],
                            "iconClass": "class55",
                            "interValue": "url55",
                            "menuId": 8,
                            "menuUrl": "url55",
                            "parentId": 2
                        },
                        {
                            "children": [],
                            "iconClass": "class11",
                            "interValue": "url11",
                            "menuId": 9,
                            "menuUrl": "url11",
                            "parentId": 2
                        }
                    ],
                    "iconClass": "class2",
                    "interValue": "url2",
                    "menuId": 2,
                    "menuUrl": "url2",
                    "parentId": -1
                },
                {
                    "children": [
                        {
                            "children": [],
                            "iconClass": "class22",
                            "interValue": "url22",
                            "menuId": 10,
                            "menuUrl": "url22",
                            "parentId": 3
                        },
                        {
                            "children": [],
                            "iconClass": "class33",
                            "interValue": "url33",
                            "menuId": 11,
                            "menuUrl": "url33",
                            "parentId": 3
                        },
                        {
                            "children": [],
                            "iconClass": "class44",
                            "interValue": "url44",
                            "menuId": 12,
                            "menuUrl": "url44",
                            "parentId": 3
                        },
                        {
                            "children": [],
                            "iconClass": "class55",
                            "interValue": "url55",
                            "menuId": 13,
                            "menuUrl": "url55",
                            "parentId": 3
                        }
                    ],
                    "iconClass": "class3",
                    "interValue": "url3",
                    "menuId": 3,
                    "menuUrl": "url3",
                    "parentId": -1
                },
                {
                    "children": [],
                    "iconClass": "class11",
                    "interValue": "url11",
                    "menuId": 4,
                    "menuUrl": "url11",
                    "parentId": -1
                }
            ],
            "message": "请求成功"
        };
        data = data1.data;
        var m = "<ul class=\"nav navbar-nav\">";
        console.log("length"+data.length);
        console.log("size"+data.size());
        if (data.length > 0) {
            for(var i=0;i<data.length;i++){
                console.log("data[i].children.length()"+data[i].children.length());
                console.log("data[i].children.size"+data[i].children.size());
                if (data[i].children.size() != null && data[i].children.length() > 0){
                    m += "<li class='ropdown'>"
                        + "  <a href='#' data-toggle='dropdown' class='dropdown-toggle'>"
                        + data[i].interValue
                        + "<span class=\"caret\"></span></a></li>";
                }
            }

        }
        $('#mymenu').html(m);
    }
    getRootmenu();
    function getSecondMenu(event) {
        var a = "<ul class='dropDown-menu menu radius box-shadow'>";
        var b = "</ul>";
        var c = "";
        var parentId = $(event).attr("id");
        var over = $(event).attr("over");
        console.log("over====" + over);
        if (!over) {
            return;
        } else {

        }
        if (data.length > 0 && parentId != null && parentId != "") {

            for (j = 0; j < data.length; j++) {
                if (data[j].parentId == parentId) {
                    c = c + "<li id='" + data[j].menuId + "'  over='false'><a href='" + data[j].menuUrl + "'>" + data[j].interValue + "</a></li>";
                }
            }
        }
        $('#' + parentId).append(a + c + b);
        $("#ulmenu li").unbind('mouseover', function (e) {
            console.log("unbind=================");
            $("#ulmenu li ul").remove();
        });
        $("#ulmenu li").bind('mouseover', function (e) {
            getSonMenu(this, e)
        });
    }

    function getThirdMenu(event) {

    }

});
